from typing import Dict, List
import pandas as pd
from datetime import datetime

def convert_to_tradingview_data(df: pd.DataFrame) -> Dict:
    """
    将DataFrame转换为TradingView所需的数据格式
    """
    df['Date'] = pd.to_datetime(df['Date'])
    return {
        "t": df['Date'].astype(int) // 10**9,  # Unix timestamp in seconds
        "o": df['Open'].tolist(),
        "h": df['High'].tolist(),
        "l": df['Low'].tolist(),
        "c": df['Close'].tolist(),
        "v": df['Volume'].tolist()
    }

def parse_tradingview_resolution(resolution: str) -> Dict:
    """
    解析TradingView的时间周期参数
    """
    units = {
        'D': 'days',
        'W': 'weeks',
        'M': 'months'
    }
    
    if resolution[-1] in units:
        num = int(resolution[:-1]) if len(resolution) > 1 else 1
        unit = units[resolution[-1]]
        return {'num': num, 'unit': unit}
    else:
        # 分钟级别
        return {'num': int(resolution), 'unit': 'minutes'} 